package com.hmall.item.web;


import com.hmall.common.result.PageResult;
import com.hmall.common.result.ResponseResult;
import com.hmall.item.dto.PageItemDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    /**
     * 商品分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    PageResult<Item> pageItem(@RequestParam Integer page, @RequestParam Integer size){
        return itemService.pageItem(page,size);
    }

    /**
     * 新增商品
     * @param item
     */
    @PostMapping
    public ResponseResult addItem(@RequestBody Item item){
      return   itemService.addItem(item);
    }

    /**
     * 商品上下架
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/status/{id}/{status}")
    public ResponseResult upOrDownItem(@PathVariable Long id, @PathVariable Integer status){
        return   itemService.upOrDownItem(id,status);
    }

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<Item> itemById(@PathVariable Long id){
        return   itemService.itemById(id);
    }

    /**
     * 修改商品
     * @param item
     * @return
     */
    @PutMapping()
    public ResponseResult modById(@RequestBody Item item){
        return  itemService.modById(item);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delItem(@PathVariable Long id){
        return  itemService.delItem(id);
    }



}
